package com.redteam.xomtro.fragment;

import android.graphics.Typeface;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.AbsListView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.redteam.xomtro.MasterActivity;
import com.redteam.xomtro.R;
import com.redteam.xomtro.views.EDGirdView;

public class PlaceTabFragment extends Fragment implements EDGirdView.OnDetectScrollListener {
    public static int CREATE_MODE = 1;
    public static int EDIT_MODE = 2;

    public ActionBar actionBar;
    public View emptyView;
    protected DisplayImageOptions options;
    protected DisplayImageOptions optionsAvatar;
    protected ImageLoader imageLoader;
    public FragmentManager fragmentManager;
    public MasterActivity activity;
    public static Typeface fontSLight;
    public static Typeface fontBold;

    public PlaceTabFragment newInstance(MasterActivity mainActivity) {
        this.activity = mainActivity;
        this.actionBar = mainActivity.getSupportActionBar();
        this.fragmentManager = mainActivity.getSupportFragmentManager();
        emptyView = mainActivity.getLayoutInflater().inflate(R.layout.empty_view, null);
        fontSLight = mainActivity.fontSLight;
        fontBold = Typeface.createFromAsset(mainActivity.getAssets(), "fonts/segoeui_sb.ttf");
        imageLoader = mainActivity.imageLoader;
        options = mainActivity.options;
        optionsAvatar = mainActivity.optionsAvatar;
        return this;
    }

    protected void beginTransaction(PlaceTabFragment fragment) {
        fragmentManager.beginTransaction()
                .setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
                .replace(R.id.fmPlaceContent, fragment)
                .commit();
    }

    @Override
    public void onLowMemory() {
        System.gc();
        imageLoader.stop();
        imageLoader.clearDiscCache();
        imageLoader.clearMemoryCache();
    }

    public void onUpScrolling() {

    }

    public void onDownScrolling() {

    }

    @Override
    public void onUpScrolling(AbsListView absListView, int firstVisibleItem) {
        actionBar.show();
    }

    @Override
    public void onDownScrolling(AbsListView absListView, int firstVisibleItem) {
        if (firstVisibleItem != 0)
            actionBar.hide();
    }
}
